<?php
require_once '../../../vendor/autoload.php';

use phpspider\core\phpspider;
use phpspider\core\requests;
use phpspider\core\selector;

/* Do NOT delete this comment */
/* 不要删除这段注释 */

$configs = array(
    'name' => 'Youtube',
    'log_show' => false,
    'log_file' => '/data/spider/youtube_spider_test.log',
//    'save_running_state' => true,
    'tasknum' => 1,
//    'max_depth' => 5,
    //数据库配置
    'db_config' => array(
        'host'  => '127.0.0.1',
        'port'  => 3306,
        'user'  => 'root',
        'pass'  => 'wewrjjdsl@oo888rmds',
        'name'  => 'youtube',
    ),
    'queue_config' => array(
        'host' => '127.0.0.1',
        'port' => 6379,
        'pass' => '',
        'db' => 1,
        'prefix' => 'phpspider',
        'timeout' => 30,
    ),
    /*'export' => array(
        'type' => 'csv',
        'file' => './data/Youtube.csv', // data目录下
    ),*/
    'export' => array(
        'type' => 'db',
        'table' => 'user',  // 如果数据表没有数据新增请检查表结构和字段名是否匹配
    ),
//爬取的域名列表
    'domains' => array(
        'youtube',
        'www.youtube.com'
    ),
//抓取的起点
    'scan_urls' => array(
        'https://www.youtube.com/'
    ),
//列表页实例
    'list_url_regexes' => array(
        "https://www.youtube.com/results?search_query=老鹰+&sp=EgIQAg%253D%253D"
    ),
//内容页实例
    'content_url_regexes' => array(
        "https://www.youtube.com/user/[A-Za-z0-9]+",
    ),
    'max_try' => 1,

    'fields' => array(
        array(
            'name' => "name",
            'selector' => "//a[@class='spf-link branded-page-header-title-link yt-uix-sessionlink']",
            'required' => true,
        ),
        array(
            'name' => "channel_id",
            'selector' => "//meta[@itemprop='channelId']/@content",
            'required' => true,
        ),
        array(
            'name' => "fans_num",
            'selector' => "//span[@class='yt-subscription-button-subscriber-count-branded-horizontal subscribed yt-uix-tooltip']",
            'required' => false,
        ),
        array(
            'name' => "view_count",
            'selector' => "//span[@class='about-stat']//b",
            'required' => false,
        ),
        array(
            'name' => "description",
            'selector' => "//div[@class='about-description branded-page-box-padding']//pre",
            'required' => false,
        ),
        array(
            'name' => "country",
            'selector' => "//span[@class='country-inline']",
            'required' => false,
        ),
        array(
            'name' => "register_time",
            'selector' => "//span[@class='about-stat'][last()]",
            'required' => false,
        ),
        array(
            'name' => "head_img",
            'selector' => "//img[@class='appbar-nav-avatar']/@src",
            'required' => false,
        ),
    ),
);

$spider = new phpspider($configs);
$spider->start();




